import {defineStore} from "pinia";
import {loginApi, updateUserInfoApi} from "../apis/userApi.js";
import {User} from "../pojo/User.js";
import {ref} from "vue";


export const useUserStore = defineStore('userStore', () => {

    const userInfo = ref(new User())

    const getLogin = async (userAccount, userPassword) => {
        console.log("开始调用")
        const resp = await loginApi(userAccount, userPassword)

        //保存user登录信息
        userInfo.value = resp.data.data
        console.log('userInfo为：', userInfo.value)
        return resp.data
    }

    const updateUser = async (user) => {
        const resp = await updateUserInfoApi(user)
        //重新保存user登录信息
        userInfo.value = resp.data.data
        console.log(resp)
        return resp.data
    }


    return {
        getLogin,
        updateUser,
        userInfo
    }

}, {
    persist: true
})

